package com.diudiutechnology.www.yadiudiu.yadiudiu.singlecall.MyAdapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.diudiutechnology.www.yadiudiu.R;
import com.diudiutechnology.www.yadiudiu.yadiudiu.singlecall.MyActivity.CreditTutorialBean;
import com.diudiutechnology.www.yadiudiu.yadiudiu.singlecall.MyActivity.DetailsCreditActivity;

import java.util.ArrayList;
import java.util.List;

import static com.diudiutechnology.www.yadiudiu.yadiudiu.singlecall.MyActivity.CreditTutorialActivity.GO_DETAIL;

/**
 * Created by Administrator on 2017/8/22.
 * 信贷列表
 */

public class CreditTutorialActivityAdapter extends BaseAdapter {

    private Context mContext;

    List<CreditTutorialBean> mBean = new ArrayList<>();

    public CreditTutorialActivityAdapter(Context context, List<CreditTutorialBean> bean) {
        this.mContext = context;
        this.mBean = bean;
    }

    @Override
    public int getCount() {
        return mBean.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public void addItem(List<CreditTutorialBean> model) {
        this.mBean = model;
        notifyDataSetChanged();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.itme_credit_tutorial, null);
            holder.item_time = (TextView) convertView
                    .findViewById(R.id.item_time);
            holder.item_type = (TextView) convertView
                    .findViewById(R.id.item_type);
            holder.item_content = (TextView) convertView
                    .findViewById(R.id.item_content);
            holder.positioning_text = (TextView) convertView
                    .findViewById(R.id.positioning_text);
            holder.browse_text = (TextView) convertView
                    .findViewById(R.id.browse_text);
            holder.item_headings = (TextView) convertView
                    .findViewById(R.id.item_headings);
            holder.go_detail = (RelativeLayout) convertView.findViewById(R.id.go_detail);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final CreditTutorialBean bean = mBean.get(position);
        holder.item_headings.setText(bean.credit_title);
        holder.item_content.setText(bean.subject);
        holder.item_time.setText(bean.add_time);
        holder.positioning_text.setText(bean.watch);
        holder.browse_text.setText(bean.paycount);
        holder.go_detail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, DetailsCreditActivity.class);
                intent.putExtra(GO_DETAIL, bean);
                mContext.startActivity(intent);
            }
        });
        return convertView;
    }

    class ViewHolder {
        TextView browse_text;
        TextView positioning_text;
        TextView item_time;
        TextView item_content;
        TextView item_headings;
        TextView item_type;
        RelativeLayout go_detail;

    }
}

